package lab3.io;

import config.ATMData;
import config.Config;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerThroughPutIO {

    /**
     * When client connected to server,
     * Server send objects to client.
     * Client calculate number of getting objects per second
     *
     * @param args
     */
    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(Config.PORT);) {
            System.out.println("Waiting for client on port " + serverSocket.getLocalPort() + "...");
            try (Socket client = serverSocket.accept()) {
                System.out.println("Just connected to " + client.getRemoteSocketAddress());
                try (ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream())) {
                    while (true) {
                        out.writeObject(ATMData.generate());
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}